import pymssql
from tools import config
from tools import mssqlHelper,mysqlHelper

server = config.mssqldbinfo['host']
user = config.mssqldbinfo['user']
password = config.mssqldbinfo['passwd']
db = config.mssqldbinfo['db']

def t_mssql_01():
    pass

def t_mssql_02():
    conn = pymssql.connect(server, user, password, db)
    cursor = conn.cursor()
    cursor.execute('SELECT TOP 10 [date1],[date2],[date3] FROM [dw].[dbo].[dim_date]')
    row = cursor.fetchone()
    while row:
        print("date1=%s, date2=%s" % (row[0], row[1]))
        row = cursor.fetchone()
    conn.close()

def t_mssql_03():
    sql ='''SELECT TOP 10 [date1],[date2],[date3] FROM [dw].[dbo].[dim_date]'''
    fetchall= mssqlHelper.getdata(sql)
    return fetchall

def t_mssql_04():
    sql ='''SELECT a.product_type,orderamount FROM tmp_order_stat a ORDER  BY 1'''
    fetchall= mysqlHelper.getdata(sql,False)
    pt=[]
    om=[]
    dic={}
    for obj in fetchall:
        pt.append(obj[0])
        om.append(obj[1])

    dic['product_type']=pt
    dic['orderamount']=om
    print dic

if __name__ == '__main__':
     t_mssql_04()